package com.framework.admin.repository;

import com.framework.admin.model.ModuleTableField;
import com.framework.common.repository.BaseJpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;


/**
 * @description: 模块数据表字段 Repository
 * @author: lizurong
 * @version: 1.0
 * @date: 2021-03-24 11:18:24
 */

@Repository
public interface ModuleTableFieldRepository extends BaseJpaRepository<ModuleTableField, String> {

    @Modifying
    @Transactional
    @Query("update ModuleTableField t set t.tableName=:newTableName where t.tableName=:oldTableName")
    void updateByTableName(@Param("newTableName") String newTableName, @Param("oldTableName") String oldTableName);


    ModuleTableField getTopByColumnNameAndTableName(String columnName, String tableName);

    @Transactional
    @Modifying
    @Query("delete from ModuleTableField t where t.tableName=:tableName")
    void deleteAllByTableName(@Param("tableName") String tableName);

    List<ModuleTableField> getListByTableName(String tableName);
}
